<?
function getUserID($username) {
	$query = "SELECT ID FROM Users WHERE Username='$username'";
	$result = mysql_query($query);
	if (mysql_num_rows($result) == 0) {
		return -1;
	}
	else {
		$row = mysql_fetch_array($result);
		return $row[0];
	}
}

function getTotalSites($userID) {
	$query = "SELECT Value FROM User_Profiles WHERE Owner=$userID AND Attribute='Total Sites'";
	$result = mysql_query($query);
	if (mysql_num_rows($result) == 0) { // no record -- create one
		$query = "INSERT INTO User_Profiles(Owner, Attribute, Value, Date_Created) VALUES ($userID, 'Total Sites', '5', '".date("Y-m-d")."');";
		mysql_query($query); 
		return 1;
	}
	else {
		$row = mysql_fetch_array($result);
		return $row[0];
	}
}

function updateTotalSites($userID, $value) {
	$query = "UPDATE User_Profiles SET Value='$value' WHERE Owner=$userID AND Attribute='Total Sites'";
	$result = mysql_query($query);
}


function getTotalCreatedSites($username) {
	$query = "SELECT count(*) FROM User_Blogs WHERE Username='$username'";
	$result = mysql_query($query);
	$row = mysql_fetch_array($result);
	return $row[0];
}

function getUserNetworkGroupStatus($userID) {
	$query = "SELECT ID FROM Network_Groups WHERE Status='Premium'";
	
	//echo $query;echo "<br>";
	
	$result = mysql_query($query);
	if (mysql_num_rows($result) == 0) {
		return -1;
	}
	else {
		$row = mysql_fetch_array($result);
			$group_id = $row['ID'];
			$query2 = "SELECT User_ID, Owner FROM Network_Groups_Users WHERE Group_ID='$group_id'";
			
		//echo $query2;echo "<br>";

			$result2 = mysql_query($query2);
			
			if(mysql_num_rows($result2) == 0)
				return -2;
			
			while($row2 = mysql_fetch_array($result2))
			{
			//echo $userID;  echo "<br>"; echo $row2['User_ID']; echo "<br>"; echo $row2['Owner'];echo "<br>";
			if(($row2['User_ID'] == $userID) || ($row2['Owner'] == $userID))
				return 1;
			}

		return -1;
	}
}

?>